home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
wics.zip
/
SBAR.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-03
|
6KB
|
260 lines
//==============================================================================================
//
// Windows Interface Construction Set
// Version 1.00
//
// SBAR.CPP - Status Bar Class
// Copyright ⌐ 1993 by Microdyne Development Technologies
// All rights reserved.
//==============================================================================================
#include "sbar.h"
#include "string.h"
TStatusBar::TStatusBar (PTWindowsObject AParent, WORD wHeight) :
TWindow (AParent, NULL)
{
Attr.Id = 20;
Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_CLIPCHILDREN;
Attr.X = -1;
Attr.Y = -1;
Attr.W = 10;
Attr.H = ( wHeight ) ? wHeight : 20 ;
wAreas = 0;
hAreaText[10] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, 1);
clrText[10] = 0 ;
SetFlags(WB_MDICHILD, FALSE);
}
TStatusBar::~TStatusBar ()
{
int i;
for (i=0 ; i < wAreas ; i++)
{
LocalFree (hAreaText[i]);
}
LocalFree (hAreaText[10]);
}
void TStatusBar::GetWindowClass(WNDCLASS& WndClass)
{
TWindow::GetWindowClass( WndClass );
WndClass.hbrBackground = GetStockObject (LTGRAY_BRUSH); ;
}
void TStatusBar::AppendArea (WORD length, LPSTR AString, COLORREF clrRef)
{
rArea[wAreas] = length;
clrText[wAreas] = clrRef ;
if ( AString )
{
hAreaText[wAreas] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, _fstrlen(AString)+1);
LPSTR pDest = LocalLock (hAreaText[wAreas]);
_fstrcpy (pDest, AString);
LocalUnlock(hAreaText[wAreas]);
}
else
{
hAreaText[wAreas] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, 1);
}
wAreas++;
InvalidateRect (HWindow, NULL, TRUE);
UpdateWindow (HWindow);
}
BOOL TStatusBar::SetAreaText (WORD AreaId, LPSTR ANewString)
{
int n, xl, xr, i, j ;
RECT rUpdate;
RECT WndRect;
GetClientRect (HWindow, &WndRect);
n = ( AreaId < wAreas ) ? AreaId : 10 ;
LocalFree (hAreaText[n]);
if ( ANewString )
{
hAreaText[n] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, _fstrlen(ANewString)+1);
LPSTR pDest = LocalLock (hAreaText[n]);
_fstrcpy (pDest, ANewString);
LocalUnlock(hAreaText[n]);
}
else
hAreaText[n] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, 1);
rUpdate.left = WndRect.left + 1;
rUpdate.right = 0 ;
j = 4 ;
for (i = 0 ; i < n && i < wAreas ; i++)
{
j = 6 ;
rUpdate.left = rArea[i] ;
}
if (n >= wAreas-1)
rUpdate.right = WndRect.right - 2 ;
else
rUpdate.right = rUpdate.left + rArea[i+1] - 1 ;
rUpdate.left += j;
rUpdate.top = WndRect.top+3;
rUpdate.bottom = WndRect.bottom-5;
InvalidateRect (HWindow, &rUpdate, TRUE);
UpdateWindow (HWindow);
return TRUE ;
}
BOOL TStatusBar::SetAreaTextColor (WORD AreaId, COLORREF clrRef)
{
if ( AreaId < wAreas || AreaId == 10 )
{
clrText[AreaId] = clrRef ;
InvalidateRect (HWindow, NULL, TRUE);
UpdateWindow (HWindow);
return TRUE;
}
return FALSE ;
}
BOOL TStatusBar::SetAreaWidth (WORD AreaId, WORD wWidth)
{
if ( AreaId < wAreas )
{
rArea[AreaId] = wWidth ;
InvalidateRect (HWindow, NULL, TRUE);
UpdateWindow (HWindow);
return TRUE;
}
return FALSE ;
}
BOOL TStatusBar::RemoveArea (WORD AreaId)
{
if (AreaId < wAreas - 1)
{
LocalFree (hAreaText[AreaId]);
for (int i = AreaId + 1 ; i < wAreas ; i++)
{
rArea[i-1] = rArea[i] ;
hAreaText[i-1] = hAreaText[i];
clrText[i-1] = clrText[i];
}
wAreas--;
}
else
{
if ( AreaId == wAreas - 1 )
{
wAreas--;
LocalFree (hAreaText[wAreas]);
}
else
return FALSE ;
}
InvalidateRect (HWindow, NULL, TRUE);
UpdateWindow (HWindow);
return TRUE ;
}
void TStatusBar::Paint (HDC hdc, PAINTSTRUCT&)
{
RECT WndRect;
RECT TextRect;
HPEN hGrayPen;
WORD x;
WORD i;
WORD n;
HFONT hLabelFont, hOldFont ;
LPSTR pText;
GetClientRect (HWindow, &WndRect);
FrameRect (hdc, &WndRect, GetStockObject(BLACK_BRUSH));
hLabelFont = CreateFont (12, 0, 0, 0, 700, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, // cOutputPrecision
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_SWISS | VARIABLE_PITCH,
(LPSTR) "Arial");
WndRect.left += 2;
WndRect.right--;
WndRect.top += 2;
WndRect.bottom-=2;
FrameRect (hdc, &WndRect, GetStockObject (GRAY_BRUSH));
WndRect.left--;
WndRect.right--;
WndRect.top--;
WndRect.bottom--;
FrameRect (hdc, &WndRect, GetStockObject(WHITE_BRUSH));
WndRect.left--;
WndRect.right += 2;
WndRect.top--;
WndRect.bottom +=3;
hGrayPen = CreatePen (PS_SOLID, 1, 0x808080);
hOldFont = SelectObject (hdc, hLabelFont);
SetBkColor (hdc, 0x0C0C0C0);
x = WndRect.left+1;
for (i=0, x=WndRect.left+1; i < wAreas; i++)
{
x += rArea[i];
SelectObject (hdc, GetStockObject(WHITE_PEN));
MoveTo (hdc, x, WndRect.bottom-4);
LineTo (hdc, x, WndRect.top+1);
MoveTo (hdc, x+2, WndRect.bottom-4);
LineTo (hdc, x+2, WndRect.top+1);
SelectObject (hdc, hGrayPen);
MoveTo (hdc, x+1, WndRect.bottom-3);
LineTo (hdc, x+1, WndRect.top);
MoveTo (hdc, x+3, WndRect.bottom-5);
LineTo (hdc, x+3, WndRect.top+1);
SetTextColor (hdc, clrText[i]);
n = (i==0) ? 4 : 6 ;
pText = LocalLock (hAreaText[i]);
TextRect.left = x - rArea[i] + n;
TextRect.right = x-1;
TextRect.top = WndRect.top+3;
TextRect.bottom = WndRect.bottom-5;
ExtTextOut (hdc, x - rArea[i]+n, WndRect.top+3, ETO_CLIPPED, &TextRect, pText, _fstrlen(pText), NULL);
LocalUnlock (hAreaText[i]);
}
SetTextColor (hdc, clrText[10]);
pText = LocalLock (hAreaText[10]);
TextRect.left = TextRect.right+2;
TextRect.right = WndRect.right-2;
TextRect.top = WndRect.top+3;
TextRect.bottom = WndRect.bottom-5;
x = TextRect.left + 4 ;
ExtTextOut (hdc, x, WndRect.top+3, ETO_CLIPPED, &TextRect, pText, _fstrlen(pText), NULL);
LocalUnlock (hAreaText[10]);
SelectObject (hdc, hOldFont);
SelectObject (hdc, GetStockObject (BLACK_PEN));
DeleteObject (hGrayPen);
DeleteObject (hLabelFont);
}
WORD TStatusBar::GetHeight ()
{
return Attr.H;
}